//
//  ANServicesTableViewController.m
//  Ants
//
//  Created by ZHM on 16/7/16.
//  Copyright © 2016年 ZHM. All rights reserved.
//

#import "ANServicesTableViewController.h"
#import "ANProfieleHeader.h"

@interface ANServicesTableViewController ()

@property (nonatomic, strong) NSArray *services;

@end

@implementation ANServicesTableViewController

- (NSArray *)services {
    if (!_services) {
        NSString *servicesPath = [[NSBundle mainBundle] pathForResource:@"services" ofType:@"plist"];
        NSMutableDictionary *dic = [[NSMutableDictionary alloc] initWithContentsOfFile:servicesPath];
        _services = [dic objectForKey:@"services"];
    }
    return _services;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.title = @"支持服务";
    self.tableView.backgroundColor = UIColorFromRGB(0xeeeeee);
    [self setUpGroup_1];
}

- (void)setUpGroup_1 {
    NSMutableArray *arrayM = [NSMutableArray array];
    for (int i = 0; i < self.services.count; i++) {
        ANCheakItem *item = [ANCheakItem itemWithTilte:_services[i]];
        item.cheak = NO;
        for (NSString *server in _selectServices) {
            if ([server isEqualToString:_services[i]]) item.cheak = YES;
        }
        [arrayM addObject:item];
    }
    ANGuoupItem *group = [[ANGuoupItem alloc] init];
    group.headedTitle = @"选择商品支持服务";
    group.items = arrayM;
    [self.guoups addObject:group];
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    ANGuoupItem *group = self.guoups[indexPath.section];
    ANCheakItem *cheakItem  = group.items[indexPath.row];
    if (cheakItem.cheak) {
        cheakItem.cheak = NO;
    }else {
        cheakItem.cheak = YES;
    }
    [self.tableView reloadData];
}

- (void)viewWillDisappear:(BOOL)animated {
    [super viewWillDisappear:animated];
    if ([self.delegate respondsToSelector:@selector(servicesSelectFinish:)]) {
        [self.delegate servicesSelectFinish:self.guoups];
    }
}

- (void)dealloc {
    ANLog(@"管理界面消失:%s",__func__);
}
@end
